package com.uam.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uam.common.annotation.Log;
import com.uam.db.model.vo.UserListVO;
import com.uam.service.PointService;
import com.uam.web.common.model.BusinessType;
import com.uam.web.common.model.PageRes;
import com.uam.web.common.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author uam
 * @create 2023/12/3 13:45
 * @email uam@uam.com
 */
@Api(tags = "点数据处理")
@RestController
@RequestMapping("/point")
public class PointController {

    @Autowired
    private PointService pointService;

    @Log(title = "上传点数据")
    @ApiOperation(value = "上传点数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户登录token", paramType = "header"),
            @ApiImplicitParam(name = "data", value = "数据", dataTypeClass = String.class),
    })
    @PostMapping("/upload/str")
    // @PreAuthorize("@customExpression.hasAuthority('sys:user:list')")
    @ResponseBody
    public Result upload(@RequestParam(required = true) String data) {

        return pointService.upload(data);
        //   return Result.createSuccess(userListVOPageRes);
    }

    @Log(title = "上传点数据")
    @ApiOperation(value = "上传点数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户登录token", paramType = "header"),
            @ApiImplicitParam(name = "file", value = "数据", dataTypeClass = MultipartFile.class),
    })
    @PostMapping("/upload/file")
    // @PreAuthorize("@customExpression.hasAuthority('sys:user:list')")
    @ResponseBody
    public Result uploadFile(@RequestPart(value = "file") MultipartFile file) {

        return pointService.uploadFile(file);
        //   return Result.createSuccess(userListVOPageRes);
    }


    @Log(title = "查询点数据信息", businessType = BusinessType.QUERY_LOG)
    @ApiOperation(value = "获取点数据信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户登录token", paramType = "header"),
            @ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "Integer", defaultValue = "0", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "分页条数", dataType = "Integer", defaultValue = "10", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pointName", value = "分页条数", dataType = "String", defaultValue = "10", dataTypeClass = String.class),

    })
    @PostMapping("/list")
    // @PreAuthorize("@customExpression.hasAuthority('sys:user:list')")
    @ResponseBody
    public Result list(@RequestParam(required = false) Integer pageNum,
                       @RequestParam(required = false) Integer pageSize,
                       @RequestParam(required = false) String pointName) {

        return pointService.list(pageNum, pageSize, pointName);
    }

}
